﻿namespace A14_Ex01_5
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    public class LexicographicAnalyzer
    {
        private const char k_SpaceChar = ' ';
        private static int m_NumOfLowerChars = 0;
        private static int m_NumOfUpperChars = 0;
        private static int m_NumOfDigitsChars = 0;
        private static int m_NumOfSpacesChars = 0;
        private static string m_AnalyzedStr = string.Empty;

        public static void Analyze(string i_StrToAnalyze)
        {
            if (isValidStrFromUser(i_StrToAnalyze))
            {
                m_AnalyzedStr = i_StrToAnalyze;
                char currentCharInStrToAnalyze;

                for (int i = 0; i < i_StrToAnalyze.Length; i++)
                {
                    currentCharInStrToAnalyze = i_StrToAnalyze[i];

                    if (Char.IsLower(currentCharInStrToAnalyze))
                    {
                        m_NumOfLowerChars++;
                    }
                    else if (Char.IsUpper(currentCharInStrToAnalyze))
                    {
                        m_NumOfUpperChars++;
                    }
                    else if (Char.IsDigit(currentCharInStrToAnalyze))
                    {
                        m_NumOfDigitsChars++;
                    }
                    else if (currentCharInStrToAnalyze.Equals(k_SpaceChar))
                    {
                        m_NumOfSpacesChars++;
                    }
                }
            }
        }

        private static bool isValidStrFromUser(string i_StrToValidate)
        {
            bool result = true;

            if (i_StrToValidate == null)
            {
                result = false;
            }

            return result;
        }

        public static void printAnalyzeResult()
        {
            System.Console.WriteLine(
@"Lexicographic Analyzer results:{0}
Number of lower chars is: {1}{0}
Number of upper chars is: {2}{0}
Number of digits chars is: {3}{0}
Number of space chars is: {4}{0}",
                     System.Environment.NewLine,
                     LexicographicAnalyzer.m_NumOfLowerChars,
                     LexicographicAnalyzer.m_NumOfUpperChars,
                     LexicographicAnalyzer.m_NumOfDigitsChars,
                     LexicographicAnalyzer.m_NumOfSpacesChars);
        }
    }
}
